package com.javasm.process.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.process.dao.ProcessTaskMapper;
import com.javasm.process.entity.ProcessTask;
import com.javasm.process.service.ProcessTaskService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProcessTaskServiceimpl extends ServiceImpl<ProcessTaskMapper, ProcessTask> implements ProcessTaskService {

    @Override
    public List<ProcessTask> getTaskList(String applyid) {
        QueryWrapper w = new QueryWrapper();
        w.eq("apply_id",applyid);
        List<ProcessTask> list = list(w);
        return list;
    }

    @Override
    public void endTask(String defName, ProcessTask task, String loginUserName) {
        UpdateWrapper w = new UpdateWrapper();
        w.eq("apply_id",task.getApplyId());
        w.eq("task_user",loginUserName);
        w.eq("process_name",defName);
        w.isNull("task_end");

        w.set("task_end", DateUtil.now());
        w.set("approve_result",task.getApproveResult());
        w.set("approve_content",task.getApproveContent());
        update(w);
    }
}
